fix: field value updates may fail multiple times - #754
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Walkthrough此次更改在 Changes字段值更新
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Field.tsx (1)
608-622: 引入curValue合理,但可再压缩一次getValue调用当前实现先在
getControlled开头计算了const value = this.getValue();,随后在触发器内再次执行this.getValue()得到curValue。
虽然两次调用都很轻量,但在高频输入场景仍是一次不必要的遍历(getFieldsValue(true)会克隆整棵 store)。可以直接删除最前面的value变量,改为在外层利用curValue,从而避免一次冗余读取,逻辑上也更统一。- const value = this.getValue(); + // 延后到真正渲染子节点时再取值,避免后续再次读取其余修改(归一化及比较均改用最新值)完全解决了 #753 的时序问题,👍。
tests/field.test.tsx (1)
76-108: 测试覆盖到位,但等待方式仍有潜在隐患
await act(async () => timeout())依赖固定 10 ms 定时器,若后续实现改为批量更新或启用flushSync,该时长可能不足/过多导致偶发失败。
建议改用 Testing Library 提供的waitFor或findBy系列 API 监听实际 DOM 变动,而不是硬编码时间。- await act(async () => { - await timeout(); - }); + await waitFor(() => + expect(form.current?.getFieldValue('input')).toBe('A'), + );这样既能保证可靠性,也能让测试速度随实现自动收敛。
代码其余部分无问题,成功重现并验证修复效果。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Field.tsx(2 hunks)tests/field.test.tsx(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/field.test.tsx (3)
src/interface.ts (1)
FormInstance(254-276)tests/common/InfoField.tsx (1)
Input(9-11)tests/common/timeout.ts (1)
timeout(3-7)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #754 +/- ##
=======================================
Coverage 99.54% 99.54%
=======================================
Files 20 20
Lines 1328 1329 +1
Branches 329 329
=======================================
+ Hits 1322 1323 +1
Misses 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| const MockBtnInput = props => ( | ||
| <> | ||
| <Input {...props} /> | ||
| <button |
There was a problem hiding this comment.
| <button | |
| <button type="button" |
There was a problem hiding this comment.
其他 button 也没加 type,看起来不是必要的
| await act(async () => { | ||
| await timeout(); | ||
| }); |
There was a problem hiding this comment.
| await act(async () => { | |
| await timeout(); | |
| }); |
这个应该不必要吧?
There was a problem hiding this comment.
从其他测试用例抄的。从感官上觉得可以留着,避免误以为更新时序问题
|
再rebase下重新跑下CI |
cb183e6 to
37d7d2a
Compare
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
37d7d2a to
f7a487a
Compare
fix #753
Summary by CodeRabbit
onChange(如先空字符串再输入"A")的场景,验证表单最终字段值正确反映最新变更。